/*
 * BasicLogger.java  0.4.0 / Oct 23, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.logging.simple;

import java.io.OutputStream;
import java.io.PrintStream;

import com.cute4j.logging.Logger;
import com.cute4j.logging.LoggingAdapter;

/**
 * Basic logging adapter implementation.
 *
 * @author Slobodan Vrkacevic
 * @version 0.4.0
 */
public class BasicLogger implements LoggingAdapter {

// Private Fields. -------------------------------------------------------------

  private final PrintStream out;

// Public Constructors. --------------------------------------------------------

  /**
   * Constructs new BasicLoggingAdapter object.
   */
  public BasicLogger() {
    this(System.err);
  }

  /**
   * Constructs new BasicLoggingAdapter object.
   *
   * @param printStream the print stream
   */
  public BasicLogger(PrintStream printStream) {
    if (printStream == null) {
      throw new IllegalArgumentException("Null print stream");
    }
    out = printStream;
  }

  /**
   * Constructs new BasicLoggingAdapter object.
   *
   * @param outputStream the output stream
   */
  public BasicLogger(OutputStream outputStream) {
    if (outputStream == null) {
      throw new IllegalArgumentException("Null output stream");
    }
    out = new PrintStream(outputStream);
  }

//LoggingAdapter Interface Implementation. ------------------------------------

  /**
   * {@inheritDoc}
   */
  public String getName() {
    return "Basic Logger";
  }

  /**
   * {@inheritDoc}
   */
  public boolean isLoggable(int level) {
    return true;
  }

  /**
   * {@inheritDoc}
   */
  public int getLevel() {
    return Logger.LEVEL_INFO;
  }

  /**
   * {@inheritDoc}
   */
  public void setLevel(int level) {
    // empty method body
  }

  /**
   * {@inheritDoc}
   */
  public void log(int level, String message, Throwable t) {
    if (message != null) {
      out.println(message);
    }
    if (t != null) {
      t.printStackTrace(out);
    }
  }

  /**
   * {@inheritDoc}
   */
  public void log(int level, String fileName, int lineNumber, String message,
                  Throwable t) {
    log(level, message, t);
  }

}
